<?php
namespace modules\org;

class storage
{
    static function schemas(): array
    {
        return [
            'orgs' => [
                'id' => 'identity',
                'codename' => 'string/64',
                'name' => 'string/64',
                'comment' => 'string',
            ],
        ];
    }

    static function add($q, string $codename, string $name)
    {
        return $q->table('orgs')
            ->field('codename', 'name', 'comment')
            ->insert($codename, $name, '');
    }

    static function delete($q, int $id)
    {
        return $q->table('orgs', $id)
            ->delete();
    }

    static function info($q, int $id)
    {
        return $q->table('orgs', $id)
            ->field('name', 'codename', 'comment')
            ->select(0);
    }

    static function id_from_codename($q, string $codename)
    {
        return $q->table('orgs')
            ->where(['codename', $codename])
            ->field('id')
            ->select(0);
    }

    static function edit($q, int $id, string $name, string $comment)
    {
        return $q->table('orgs', $id)
            ->field('name', 'comment')
            ->update($name, $comment);
    }
}

